//
// Commande.cpp for Plazza in /home/seth/C++/pizzaillo
// 
// Made by kevin lansel
// Login   <lansel_k@epitech.net>
// 
// Started on  Wed Apr 17 14:27:10 2013 kevin lansel
// Last update Wed Apr 17 16:12:51 2013 kevin lansel
//

#include	<algorithm>
#include	<sstream>
#include	"Commande.hpp"

Commande::Commande(int id, const std::string &commande) : _id(id), _commande(commande)
{
  std::list<CompoCmd>	compo;
  std::stringstream	ss;
  std::string		tmp;

  compo = Lexer::listing(commande);
  ss << id;
  for (std::list<CompoCmd>::iterator it = compo.begin() ; it != compo.end() ; ++it)
    {
      while (it->nb > 0)
	{
 	  this->_pizzas.push_back((it->cmd + " " + ss.str()));
	  it->nb--;
	  this->_nb += 1;
	}
    }
  ss.clear();
  ss.str("");
}

Commande::~Commande()
{
}

int				Commande::getId() const
{
  return (this->_id);
}

std::string			Commande::getCommande() const
{
  return (this->_commande);
}

int				Commande::getNb() const
{
  return (this->_nb);
}

std::list<std::string>	Commande::getPizzas() const
{
  return (this->_pizzas);
}

void				Commande::setId(int id)
{
  this->_id = id;
}

void				Commande::setCommande(const std::string &commande)
{
  this->_commande = commande;
}

void				Commande::setNb(int nb)
{
  this->_nb = nb;
}

void				Commande::setPizzas(std::list<std::string> pizzas)
{
  this->_pizzas = pizzas;
}

bool				Commande::checkstate() const
{
  if (this->_nb <= 0)
    return (true);
  else
    return (false);
}

void				Commande::removepizza(const std::string &pizza)
{
  std::list<std::string>::iterator	it;

  it = find(this->_pizzas.begin(), this->_pizzas.end(), pizza);
  if (it != this->_pizzas.end())
    this->_pizzas.erase(it);
  else
    throw("Sorry, Luigi eat all the Pizzas, we can't find yours. MamaMia");
}

